package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Phone     string `gorm:"type:varchar(20);not null;comment:'手机号'"`
	Password  string `gorm:"type:varchar(32);not null;comment:'密码'"`
	NickName  string `gorm:"type:varchar(30);not null;comment:'昵称'"`
	HeadImage string `gorm:"type:varchar(500);not null;comment:'头像'"`
	Status    int    `gorm:"type:tinyint;not null;comment:'账号状态'"`
	FollowNum int    `gorm:"type:int;not null;comment:'关注数'"`
	FansNum   int    `gorm:"type:int;not null;comment:'粉丝数'"`
}

func (u *User) Register(db *gorm.DB) error {
	return db.Debug().Create(u).Error
}

func (u *User) FindUserByMobile(db *gorm.DB, mobile string) error {
	return db.Debug().Where("phone = ?", mobile).Find(u).Error
}

func (u *User) PasswordUpdate(db *gorm.DB) error {
	return db.Debug().Updates(u).Error
}

func (u *User) FindUserById(db *gorm.DB, id int64) error {
	return db.Debug().Where("id = ?", id).First(u).Error
}

func (u *User) NickNameUpdate(db *gorm.DB) error {
	return db.Debug().Updates(u).Error
}
